# Makefile for the parallel data mining project.
# Copyright Tayfun Sen http://blog.tayfunsen.com
#
# Use compiler flags such as -O3.
# For compiler options see: 
# http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Warning-Options.html

# Suppress compiler's "deprecated conversion from string constants to char *"
# type of messages via -Wno-write-strings option.

SRC= main.cpp FirstPhase.cpp
OBJS= Tree.o Globals.o Node.o ResultTree.o
CUST_OBJS= FirstPhaseSerial.o FirstPhaseMpiReduce.o FirstPhaseMpiSimpleReduce.o
# CC= mpiCC
CC= gfilt /cand:L 
IPATH= /usr/local/include/boost-1_37 
LPATH= /usr/local/lib/
LIB_MPI= boost_mpi-gcc43-mt-1_37 
LIB_SER= boost_serialization-gcc43-mt-1_37
# Uncomment -g below for debugging symbols. Do NOT use -O3 whilst debugging.
# BASARIM09 icin en iyilestirmeler kapatildi.
OTHERS= -Wno-write-strings -Wno-deprecated -O3 #-g
# "pedantic" issues all the mandatory diagnostics listed in the C std. 
# -Wall -Wextra seems to spit a lot of warnings for boost libraries.

all: cpSerial cpMpiReduce cpSimpleReduce 

# One can use backslash (\) to break long lines but it doesn't look good in 
# make output.
cpSerial: main.o FirstPhaseSerial.o SecondPhase.o $(OBJS)
	$(CC) -I $(IPATH) main.o FirstPhaseSerial.o SecondPhase.o $(OBJS) -o cpSerial -L$(LPATH) -l$(LIB_MPI) -l$(LIB_SER) $(OTHERS)

cpMpiReduce: mainMpi.o FirstPhaseMpiReduce.o SecondPhaseMpi.o $(OBJS) 
	$(CC) -I $(IPATH) mainMpi.o FirstPhaseMpiReduce.o SecondPhaseMpi.o $(OBJS) -o cpMpiReduce -L$(LPATH) -l$(LIB_MPI) -l$(LIB_SER) $(OTHERS) 

cpSimpleReduce: mainMpi.o FirstPhaseMpiSimpleReduce.o SecondPhaseMpi.o $(OBJS)
	$(CC) -I $(IPATH) mainMpi.o FirstPhaseMpiSimpleReduce.o SecondPhaseMpi.o $(OBJS) -o cpSimpleReduce -L$(LPATH) -l$(LIB_MPI) -l$(LIB_SER) $(OTHERS)

main.o: main.cpp
	$(CC) -c -I $(IPATH) -I /home/tayfun/dersler/thesis/code/libs main.cpp -o main.o $(OTHERS)

mainMpi.o: main.cpp
	$(CC) -c -I $(IPATH) -I /home/tayfun/dersler/thesis/code/libs main.cpp -o mainMpi.o $(OTHERS) -DUSE_MPI

# Do not forget! Linker input file not used because linking not done. No -L or -l here when only compiling.
FirstPhaseSerial.o: FirstPhase.cpp
	$(CC) -c -I $(IPATH) FirstPhase.cpp -o FirstPhaseSerial.o $(OTHERS)

FirstPhaseMpiReduce.o: FirstPhase.cpp
	$(CC) -c -I $(IPATH) FirstPhase.cpp -o FirstPhaseMpiReduce.o $(OTHERS) -DUSE_MPI

FirstPhaseMpiSimpleReduce.o: FirstPhase.cpp
	$(CC) -c -I $(IPATH) FirstPhase.cpp -o FirstPhaseMpiSimpleReduce.o $(OTHERS) -DUSE_MPI -DSIMPLE_REDUCE

Tree.o: Tree.cpp
	$(CC) -c -I $(IPATH) Tree.cpp -o Tree.o $(OTHERS)

Globals.o: Globals.cpp
	$(CC) -c -I $(IPATH) Globals.cpp -o Globals.o $(OTHERS)

Node.o: Node.cpp
	$(CC) -c -I $(IPATH) Node.cpp -o Node.o $(OTHERS)

SecondPhase.o: SecondPhase.cpp
	$(CC) -c -I $(IPATH) SecondPhase.cpp -o SecondPhase.o $(OTHERS)
 
SecondPhaseMpi.o: SecondPhase.cpp
	$(CC) -c -I $(IPATH) SecondPhase.cpp -o SecondPhaseMpi.o $(OTHERS) -DUSE_MPI
 
ResultTree.o: ResultTree.cpp 
	$(CC) -c -I $(IPATH) ResultTree.cpp -o ResultTree.o $(OTHERS)

tar: 
	tar cvf parcloset.tar *.?pp libs/ Makefile.nar* scripts/
run:
	mpirun -np 2  ~/dersler/thesis/code/main -y -r -t 88161 -s 0.1

run1:
	mpirun -np 1 ~/dersler/thesis/code/main -y -a -t 88161 -s $(ARG1) $(ARG2)

run2:
	mpirun -np 2 ./cpMpiReduce -r -i input.txt.88161 -t 88161 -d 1 -s 40000

clean:
	rm *.o cpMpiReduce cpSerial cpSimpleReduce
